﻿@model LynxWiki.ViewModels.AttachmentViewData
@using LynxWiki.ViewModels

@{
    ViewBag.Title = "File Attachment Management";
}

<h2>File Attachment Management</h2>
@using (Html.BeginForm("CreateNamespace", "Attachment", FormMethod.Post, new { id = "CreateNamespace" })) {
    @Html.Label("New Namespace : ", new { @class = "inline" }) @Html.TextBoxFor(model => model.NamespaceSelected) <input type="submit" value="Create Namespace" /> <br />
    @Html.DisplayFor(m => m.NamespaceCreatedResult)<br />
    <div><a id="slick-toggle_nsprivs" href="#">Manage Namespace Privileges</a>
    <div id="slickbox_nsprivs">@Html.Label("Allow Edit Users")
    @Html.TextBoxFor(model => model.ListAllowEditUser)<br />
    @Html.Label("Allow Edit Roles")
    @Html.TextBoxFor(model => model.ListAllowEditRole)<br />
    @Html.Label("Deny Read Users")
    @Html.TextBoxFor(model => model.ListDenyReadUser)<br />
    @Html.Label("Deny Read Roles")
    @Html.TextBoxFor(model => model.ListDenyReadRole)<br /></div></div>
}
@using (Html.BeginForm("UploadFile", "Attachment", FormMethod.Post, new { id = "FileUpload", enctype = "multipart/form-data" })) {
    @Html.Label("Filename :") <input type="file" name="file" id="file" /> <input type="submit" value="Upload" />
    @Html.Label("Namespace : ", new { @class = "inline" }) @Html.DropDownListFor(model => model.NamespaceSelected, (IEnumerable<SelectListItem>)ViewBag.ListNamespacesWrite)  <br />
    <div id="ErrorMsgDiv" ></div>
    @Html.DisplayFor(m => m.FileUploadResult)<br />
    @Html.LabelFor(model => model.VersionNote)
    @Html.TextAreaFor(model => model.VersionNote)<br />
    @Html.LabelFor(model => model.Tags)
    @Html.TextAreaFor(model => model.Tags)
    <div><a id="slick-toggle_privs" href="#">Manage Privileges</a>
    <div id="slickbox_privs">@Html.Label("Allow Edit Users")
    @Html.TextBoxFor(model => model.ListAllowEditUser)<br />
    @Html.Label("Allow Edit Roles")
    @Html.TextBoxFor(model => model.ListAllowEditRole)<br />
    @Html.Label("Deny Read Users")
    @Html.TextBoxFor(model => model.ListDenyReadUser)<br />
    @Html.Label("Deny Read Roles")
    @Html.TextBoxFor(model => model.ListDenyReadRole)<br /></div></div>
}
@using (Html.BeginForm("ListFiles", "Attachment", FormMethod.Post, new { id = "ListFiles" })) {
    <fieldset id="fldListFiles">
        <legend>File Listing Selection</legend>
        @Html.Label("Namespace : ", new { @class = "inline" }) @Html.DropDownListFor(model => model.NamespaceSelected, (IEnumerable<SelectListItem>)ViewBag.ListNamespacesRead)  <br />
        @foreach (FileTypeSelection fts in Model.Selections) {
            @Html.RadioButtonFor(rb => rb.FileTypeSelected, fts.ID) @fts.FileType
        } <input type="submit" />
    </fieldset>
}
@if (Model.Files != null && Model.Files.Count > 0) {
<div style="width: 100%; max-width:960px;">    
<table class="TableClass TableCellWrap MaxWidth">
    <tr>
        <th class="TableCellHighlighted">File</th><th class="TableCellHighlighted">Size (bytes)</th><th class="TableCellHighlighted">Created On</th>
        <th class="TableCellHighlighted">WikiText Reference</th>
        @if (User.IsInRole("WikiAdmin")) {
            <th class="TableCellHighlighted">File Action</th>
        }
    </tr>
    @Html.DisplayFor(m => m.Files)
</table></div>
}
else {
<div>There are no files in this Namspace or you do not have read access to the Namespace.</div>
}
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@section Scripts {
    <script type="text/javascript" >
        $(document).ready(function () {
            $('#ErrorMsgDiv').hide();
            $('#nsErrorMsgDiv').hide();
            $('#slickbox_privs').hide();
            $('#slickbox_nsprivs').hide();
            $('#slick-toggle_privs').click(function () {
                $('#slickbox_privs').toggle(400);
                return false;
            });
            $('#slick-toggle_nsprivs').click(function () {
                $('#slickbox_nsprivs').toggle(400);
                return false;
            });
        });
    </script>
}